import maya.cmds as mc
import re
def createRecerseJnt():
    
    seleJnt=mc.ls(sl=True)
    stept=mc.intSliderGrp('createReversejnt',q=True,value=True)
    for k in seleJnt:
        mc.select(k)
        for i in range(stept):
            mc.pickWalk(d='up')
        
        parentname=mc.ls(sl=True)[0]
        splitname=str(k).split('_')    
        reversename=str(k).replace(splitname[-1],'reverse')
        
        mc.duplicate(k,n=reversename)
        mc.setAttr(str(reversename)+'.visibility',0)
        if stept>1:
            mc.parent(reversename,parentname)
def conneReverseAttr():
    skinname=mc.textFieldGrp('conneReverseAttr',q=True, text=True)
    IsAllCluters=mc.checkBox('all',q=True,v=True)
    jntConnectAll=[]
    worldMatrixAttr=[]
    
    # skinname='skinCluster6'
    connectAttrs=mc.listConnections(skinname,s=True,p=True,c=True,scn=True)
    for m in connectAttrs:
        if 'worldMatrix' in m:
            worldMatrixAttr.append(m)
    for i in worldMatrixAttr:
        ojbConnect=str(i).split('.')[0]
        jntConnectAll.append(ojbConnect)
        
        if IsAllCluters == 1:

            connectedMatrixAttr=mc.listConnections(i,d=True,p=True)

      
            for k in connectedMatrixAttr:
            
        
                bindAttr=str(k).replace('matrix','bindPreMatrix')
                splitname=str(ojbConnect).split('_')
                reversename=str(ojbConnect).replace(splitname[-1],'reverse')
        
                attrIsConnect=mc.listConnections(bindAttr,s=True)
                if attrIsConnect==None: 
                    mc.connectAttr(str(reversename)+'.worldInverseMatrix[0]',bindAttr)

        if IsAllCluters == 0:
            connectedMatrixAttrs=mc.listConnections(i,d=True,p=True)
            
            for cmas in connectedMatrixAttrs:
                if skinname in cmas:
                    connectedMatrixAttr=cmas

            orgbindAttr=str(connectedMatrixAttr).replace('matrix','bindPreMatrix')
            replacename=str(connectedMatrixAttr).split('.')[0]
            bindAttr=str(orgbindAttr).replace(replacename,skinname)
            
            splitname=str(ojbConnect).split('_')
            reversename=str(ojbConnect).replace(splitname[-1],'reverse')

            attrIsConnect=mc.listConnections(bindAttr,s=True)
            if attrIsConnect==None: 
                mc.connectAttr(str(reversename)+'.worldInverseMatrix[0]',bindAttr)
                #print(str(reversename)+'.worldInverseMatrix[0]'+'-----------'+bindAttr)